(function(win, $){
	var setFormResult = win.setFormResult = function (data) {
        console.log(data);
        layer.closeAll();
        if(data.status != 10000) {
            layer.alert(data.errmsg, {icon: 5});
        } else {
            layer.confirm('添加成功！', {icon: 6, title:'系统提示', btn: ['查看列表']}, function(index){
            	location.href = urlPbServiceList + '?id=' + bpId;
            }, function(index){
                
            });
        }
    };
    function refreshUser(parame){
        $('.user_id').html("");
        var html = '';
        for(var i= 0;i < parame.length;i++){
            var data = parame[i];
            html += "<option value='"+data.user_id+"'>"+ data.user_nickname +"</option>";
        }
        $('.user_id').html(html);
    }
	$(function(){
	    var but = $('#but_add_photo');
	    but.on('click', function(){
	        var box = $('#bp_photos_box');
	        if($(".paddingTB5").length > 4){
            	alert('最多上传五张');
            	return false;
            }
	        box.append('<div class="input-group paddingTB5"><input type="file" class="form-control" name="pics[]"><div class="input-group-addon bg_red cursor_pointer" onclick="$.bpPhotoDel(this)"><i class="fa fa-times"></i></div></div>');
	    });
	    $.extend({
	        'bpPhotoDel': function(obj) {
	            $(obj).parent().remove();
	        }
	    });
	    $('#form_add').on('valid.form', function(e, form){
	        layer.load();
	        form.submit();
	    });
	    //搜索发布人
	    //window.refreshUser = refreshUser;
	    $('.search_user').change(function() {
            var username = $('.search_user').val();
            $.ajax({
                type:'POST',
                dataType:'json',
                url:'/manage/bpinteract/searchuser',
                data:{search_user:username},
                success:function (data){
                    refreshUser(data.list);
                }
            })
        });
	});
})(window, jQuery);